<?php

namespace App\Containers\AppSection\Data\Tasks;

use App\Containers\AppSection\Data\Data\Repositories\PersonalRepository;
use App\Containers\AppSection\Data\Models\Personal;
use App\Ship\Exceptions\CreateResourceFailedException;
use App\Ship\Parents\Tasks\Task;

class CreateDefaultPersonalTask extends Task
{
    protected PersonalRepository $repository;

    public function __construct(PersonalRepository $repository)
    {
        $this->repository = $repository;
    }

    public function run(int $userId, $fio, bool $without_patronymic): Personal
    {
        try {
            return $this->repository->create([
                'user_id' => $userId,
                'fio' => $fio,
                'without_patronymic' => $without_patronymic,
            ]);
        } catch (Exception $exception) {
            throw new CreateResourceFailedException('Failed to create Personal');
        }
    }
}
